package org.noote.libs.robot.wild;

import java.util.ArrayList;

import org.noote.libs.robot.Robot_Animation;
import org.noote.libs.robot.Robot_AnimationContext;
import org.noote.libs.robot.Robot_Skeleton;

public class WildRobot_AnimationContext extends Robot_AnimationContext {

	protected WildRobot_Animation _anim;
	
	public class Factor
	{
		private String _name = "?";
		private float _value = 0;
		
		public Factor(String name)
		{
			this._name = name;
		}

		public String getName() {
			return _name;
		}

		public float getValue() {
			return _value;
		}

		public void setValue(float value) {
			this._value = value;
		}
	};
	final private ArrayList<Factor> _factors = new ArrayList<Factor>();
	
	public WildRobot_AnimationContext(Robot_Skeleton robot) {
		super(robot);
	}
	
	@Override
	public boolean start(Robot_Animation anim)
	{
		return false;
	}
	
	public boolean start(WildRobot_Animation anim)
	{
		if(!super.start(anim)) return false;
		
		_anim=anim;
		
		return _anim.startAnimation(this);
	}
	
	@Override
	public void addTime(float fSlice) {
		super.addTime(fSlice);
		
		if(_anim != null)
		{
			if(_anim.doAnimation(fSlice, this))
				_bFinished = true; 
		}
		else _bFinished = true;
	}	

	public Factor newFactor(String sName)
	{
		Factor new_factor = new Factor(sName);
		if(_factors.add(new_factor))
			return new_factor;
		return null;
	}
	public Factor getFactor(String sName)
	{
		for(Factor f : _factors)
		{
			if(f.getName().equalsIgnoreCase(sName))
				return f;
		}
		return null;
	}
}
